const app = getApp()

Page({
  data: {
  dataList:[],
  userID: '',
  userName: ''
},
  getPageList(){
    wx.showLoading({
      title: '加载中',
    })
    let db = wx.cloud.database()
    let userCollection = db.collection('squat-count')
    userCollection.where({
      id: this.data.userID
    }).get().then(res =>{
      console.log("数据查询成功", res)
      console.log("第一个数据", res.data[0])
      
      var tempList = []
      res.data.forEach((elem) => tempList.push({date: elem.date, time: elem.when, groups: elem.groupNum, amount: elem.resNum}))

       this.setData({
         dataList: tempList
       })


      console.log("dataList", this.data.dataList)
      console.log("第二个数据", res.data[1])
      wx.showToast({
        title: '加载完成',
      })
    })
  },
  onShow(){
    this.setData({
      userID: app.globalData.userID,
      userName: app.globalData.nickname,
    })
    console.log("用户ID", this.data.userID),
    console.log("用户名称", this.data.userName)
    this.getPageList()
  }
})
